package HierarchyPackage.AffixHierarchies;

import HierarchyPackage.*;
import ClassifiedDataSetPackage.ClassifiedDataSet;
import DataSetPackage.View;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 *
 * @author Martin Haulrich
 */
abstract class AffixHierarchy implements Hierarchy {

    /**
     * The top-class in the hierarchy.
     * This is equavalent to an empty string.
     */
    AffixHClass top;

    protected void setTop(AffixHClass top) {
        this.top = top;
    }

    @Override
    public HClass getTop() {
        return top;
    }

    @Override
    public String getName(HClass hc) {

        AffixHClass hcS = (AffixHClass) hc;
        String name = hcS.getID();
        if (name.equals("")) {
            return "TOP";
        } else {
            return name;
        }
    }

    @Override
    abstract public ClassifiedDataSet getClassifications(Collection<Integer> dids, View v,
            HClass topClass, int maxDepth, int minCount, int cutFracgtion, boolean saveData);

    @Override
    abstract public boolean superclassOf(HClass c1, HClass c2);

    @Override
    abstract public boolean isClassifiedBy(Integer did, View dv, HClass classification);

    public abstract HClass getIntersectionLocal(HClass c1, HClass c2);

    @Override
    public Set<HClass> getIntersection(HClass c1, HClass c2) {
        HClass c = getIntersectionLocal(c1, c2);
        
        if (c != null) {
            return Collections.<HClass>singleton(c);
        } else {
            return Collections.<HClass>emptySet();
        }
        
    }

   
}
